# ====================== vrp_model.py ======================
import numpy as np

class Customer:
    def __init__(self, id, x, y, demand, volume, early, late):
        self.id = id
        self.x = x
        self.y = y
        self.demand = demand
        self.volume = volume
        self.early = early  # 最早服务时间（分钟）
        self.late = late    # 最晚服务时间（分钟）

class Vehicle:
    def __init__(self, capacity, volume, max_range,
                 distance_cost=2.5, time_cost=0.5, fixed_cost=500,
                 overload_penalty=1000, time_penalty=200):
        self.capacity = capacity
        self.volume = volume
        self.max_range = max_range
        self.distance_cost = distance_cost    # 元/公里
        self.time_cost = time_cost            # 元/分钟
        self.fixed_cost = fixed_cost          # 元/车次
        self.overload_penalty = overload_penalty  # 超载罚金
        self.time_penalty = time_penalty      # 时间窗违反罚金

class VRPTWInstance:
    def __init__(self, customers, depot, distance_matrix, time_matrix, vehicle):
        self.customers = customers    # 客户列表（含仓库）
        self.depot = depot            # 仓库对象
        self.distance_matrix = distance_matrix  # 距离矩阵（公里）
        self.time_matrix = time_matrix          # 时间矩阵（分钟）
        self.vehicle = vehicle        # 车辆配置
        self._fitness_cache = {}      # 适应度缓存

    def clear_cache(self):
        """清空适应度缓存"""
        self._fitness_cache.clear()